package service

import (
	"myserver/dao"
	"myserver/model"
	"myserver/param"
	"myserver/tool"
)

type SubsidyService struct {
}

func (s *SubsidyService) GetSubsidy(subsidy model.Subsidy) model.Subsidy {
	var subsidyDao = dao.SubsidyDao{MyOrm: tool.MyDb}
	res := subsidyDao.GetSubsidy(&subsidy)
	if res.RowsAffected != 0 {
		return subsidy
	} else {
		return model.Subsidy{}
	}
}

func (s *SubsidyService) CreateSubsidy(subsidy model.Subsidy) int64 {
	var subsidyDao = dao.SubsidyDao{MyOrm: tool.MyDb}
	res := subsidyDao.CreateSubsidy(subsidy)
	return res
}

func (s *SubsidyService) DeleteSubsidy(subsidy model.Subsidy) int64 {
	var subsidyDao = dao.SubsidyDao{MyOrm: tool.MyDb}
	res := subsidyDao.DeleteSubsidy(subsidy)
	return res
}

func (s *SubsidyService) UpdateSubsidy(subsidy model.Subsidy) int64 {
	var subsidyDao = dao.SubsidyDao{MyOrm: tool.MyDb}
	res := subsidyDao.UpdateSubsidy(subsidy)
	return res
}

func (s *SubsidyService) QuerySubsidy(p *param.PageParam) param.ResponsePageParam {
	var subsidyDao = dao.SubsidyDao{MyOrm: tool.MyDb}
	res := subsidyDao.QuerySubsidy(tool.ToPageParam(*p))
	return res
}

func (s *SubsidyService) GetRsSubsidy(subsidy model.Subsidy) int64 {
	var subsidyDao = dao.SubsidyDao{MyOrm: tool.MyDb}
	return subsidyDao.GetRsSubsidy(subsidy)
}

func (s *SubsidyService) CreateRsSubsidy(reservation model.Reservation) int64 {
	var subsidyDao = dao.SubsidyDao{MyOrm: tool.MyDb}
	res := subsidyDao.CreateRsSubsidy(reservation)
	return res
}

func (s *SubsidyService) UserSubsidys(pageParam param.PageParam) param.ResponsePageParam {
	var subsidyDao = dao.SubsidyDao{MyOrm: tool.MyDb}
	return subsidyDao.UserSubsidys(tool.ToPageParam(pageParam))
}
